package com.ouyy.volunteerservice.volunteer.controller;

import com.ouyy.volunteerservice.volunteer.domain.po.Carousel;
import com.ouyy.volunteerservice.volunteer.service.carouselService;
import org.springframework.web.bind.annotation.*;
import org.springframework.beans.factory.annotation.Autowired;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import java.util.List;

@RestController
@RequestMapping("/carousel")
public class CarouselController {

    @Autowired
    private carouselService carouselService;

    /**
     * 获取所有轮播图列表
     */
    @GetMapping("/list")
    public List<Carousel> getAll() {
        return carouselService.list();
    }

    /**
     * 根据 ID 获取轮播图
     */
    @GetMapping("/{id}")
    public Carousel getById(@PathVariable Integer id) {
        return carouselService.getById(id);
    }

    /**
     * 添加轮播图
     */
    @PostMapping("/add")
    public boolean add(@RequestBody Carousel carousel) {


        return carouselService.save(carousel);
    }

    /**
     * 更新轮播图
     */
    @PutMapping("/update")
    public boolean update(@RequestBody Carousel carousel) {
        return carouselService.updateById(carousel);
    }

    /**
     * 根据 ID 删除轮播图
     */
    @DeleteMapping("/delete/{id}")
    public boolean delete(@PathVariable Integer id) {
        return carouselService.removeById(id);
    }

    /**
     * 分页查询轮播图
     */
    @GetMapping("/page")
    public Page<Carousel> getPage(@RequestParam(defaultValue = "1") int pageNum,
                                  @RequestParam(defaultValue = "10") int pageSize) {
        return carouselService.page(new Page<>(pageNum, pageSize));
    }
}
